package com.bupt.cad.controller;

import com.alibaba.fastjson.JSONObject;
import com.bupt.cad.common.ApiResult;
import com.bupt.cad.entity.Relationship;
import com.bupt.cad.entity.RelationshipVO;
import com.bupt.cad.service.impl.RelationshipService;
import com.bupt.cad.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class RelationshipController {

    @Autowired
    private RelationshipService relationshipService;


    //保存蓝图组件
    //1.删除所有组件
    //2.插入

    @ResponseBody
    @PostMapping(value = "/saveRelationshipSetting")
    public ApiResult saveRelationshipSetting(@RequestBody JSONObject object){
        if(relationshipService.insertRelationships(object)){
            return ResultUtil.success("save RelationshipSetting successfully");
        }
        else{
            return ResultUtil.error(-1,"save RelationshipSetting failed");
        }
    }

    @ResponseBody
    @GetMapping(value = "/getRelationshipSetting")
    public ApiResult getRelationshipSetting(@RequestParam int screenId){
        RelationshipVO relationshipVO = relationshipService.getRelationships(screenId);
        if(relationshipVO !=null){
            return ResultUtil.success(relationshipVO,"get RelationshipSetting successfully");
        }
        else{
            return ResultUtil.error(-1,"get RelationshipSetting failed");
        }
    }
}
